<?

include('../rp2/global_functions.php');

include('wallet_db.html');

$requests_between=translate('requests_between');
$and=translate('and');
$all=translate('all');
$approved=translate('approved');
$notApproved=translate('notApproved');
$rejected=translate('rejected');
$search=translate('search');
$no_data=translate('no_data');
$data=translate('data');
$amountt=translate('amountt');
$newamountt=translate('newamountt');
$ratee=translate('ratee');


if (empty($_POST[f_date])) {
        $f_date=date("Y-m-d");
        $t_date=date("Y-m-d");
} else {
        $f_date=$_POST[f_date];
        $t_date=$_POST[t_date];
}
echo "<script src='calendar.js'></script>";
$params[sid] = $sid;
$params[action] = "currencyExchangeHistory";
$url = "$baseURL/$webDIR/?".encode_params($params);
echo "<table class='bTable' cellspacing=0>
<form action=\"$url\" method=POST>
<tr>
        <td align=center>$requests_between&nbsp;
        <input type=text name=f_date id=f_date value=\"$f_date\" size=11 maxlength=10>
                <input type=button name=button value='#' onclick=\" popUpCalendar(daForm,document.getElementById('f_date'),document.getElementById('f_date'),'yyyy-mm-dd');\">&nbsp;
        $and&nbsp;
        <input type=text name=t_date id=t_date value=\"$t_date\" size=11 maxlength=10>
                <input type=button name=button value='#' onclick=\" popUpCalendar(daForm,document.getElementById('t_date'),document.getElementById('t_date'),'yyyy-mm-dd');\">&nbsp;
        <br>Show:&nbsp;<select name=by_type>
                <option value=1 "; if (empty($_POST[by_type]) or $_POST[by_type]==1) echo "selected"; echo">$all</option>
                <option value=2 "; if ($_POST[by_type]==2) echo "selected"; echo">$approved</option>
                <option value=3 "; if ($_POST[by_type]==3) echo "selected"; echo">$notApproved</option>
                <option value=4 "; if ($_POST[by_type]==4) echo "selected"; echo">$rejected</option>
        </select>
        &nbsp;<input type=submit name=submit value=\"$search\">
        <input type=hidden name=hid_search_var value=156>
        </td>
</tr>
</form>
</table><br><br>";
$by_type=!empty($_POST[by_type])?$_POST[by_type]:1;
switch ($by_type) {
        case 2:
                $where="AND temp_currency.approved='y' ";
                break;
        case 3:
                $where="AND temp_currency.approved='n' ";
                break;
        case 4:
                $where="AND temp_currency.approved='r' ";
                break;
        default:
                $where='';
}
if ($f_date!=$t_date) {
        $where .= "AND order_date BETWEEN '$f_date' AND '$t_date'";
} else {
        $where .= "AND order_date = '$t_date'";
}

//------------------------------------------------------
        $sql['type']='SELECT';
        $sql['params']='*';
        $sql['table']='temp_currency';
        $sql['where']="reseller_id='$id' ".$where;
        $sql['options']='order by order_date desc';
        $sql['return']='struct';
//------------------------------------------------------
if ($result=sql_exec($sql,'','assoc')){
        echo "<br><br><table class='bTable' cellspacing=0>
        <tr>
                <th>$data</th>
                <th>$amountt</th>
                <th>$newamountt</th>
                <th>$ratee</th>
                <th>$approved</th>
        </tr>";
        foreach($result as $value) {
                #test_array($value);
                $value[order_date]=explode(" ",$value[order_date]);
                $date=$value[order_date][0];
                switch ($value[approved]) {
                        case 'y':
                                $message="<font color=green>$approved</font>";
                                break;
                        case 'n':
                                $message="<font color=red>$notApproved</font>";
                                break;
                        case 'r':
                                $message="<font color=purple>$rejected</font>";
                                break;
                }
                echo "<tr>
                        <td align=center>$date</td>
                        <td align=center>$value[amount_from] $value[currency_from]</td>
                        <td align=center>$value[amount_to] $value[currency_to]</td>
                        <td align=center>$value[rate]</td>
                        <td align=center>$message</td>
                </tr>";
        }
        echo "</table>";
} else {
			 $errorMsg = translate('$no_data');
			 include_once('errorMsg.html');
//     echo "<h4>$no_data</h4>";
}

?>

